layui.use(['element', 'form', 'layedit','upload'], function () {
    var form = layui.form;
    var $ = layui.jquery,upload = layui.upload;

    //首页logo
    var uploadInst = upload.render({
        elem: '#btn1'
        ,url: '/admin/index/uploadFile'
        ,before: function(obj){
            //预读本地文件示例，不支持ie8
            obj.preview(function(index, file, result){
                $('#btn1_url').attr('src', result); //图片链接（base64）
            });
        }
        ,done: function(res){
            //如果上传失败
            if(res.code > 0){
                return layer.msg('上传失败');
            }
            //上传成功
            console.log(res.data.src)
            $('#HOME_BANNER').val(res.data.src);
        }
        ,error: function(){
            //演示失败状态，并实现重传
            return layer.msg('上传失败');
        }
    });

    var uploadInst = upload.render({
        elem: '#btn2'
        ,url: '/admin/index/uploadFile'
        ,before: function(obj){
            obj.preview(function(index, file, result){
                $('#btn2_url').attr('src', result); 
            });
        }
        ,done: function(res){
            if(res.code > 0){
                return layer.msg('上传失败');
            }
            console.log(res.data.src)
            $('#CAMPAIGN_BANNER').val(res.data.src);
        }
        ,error: function(){
            return layer.msg('上传失败');
        }
    });

    var uploadInst = upload.render({
        elem: '#btn3'
        ,url: '/admin/index/uploadFile'
        ,before: function(obj){
            obj.preview(function(index, file, result){
                $('#btn3_url').attr('src', result); 
            });
        }
        ,done: function(res){
            if(res.code > 0){
                return layer.msg('上传失败');
            }
            console.log(res.data.src)
            $('#NEW_BANNER').val(res.data.src);
        }
        ,error: function(){
            return layer.msg('上传失败');
        }
    });

    //about banner1
    var uploadInst = upload.render({
        elem: '#btn4'
        ,url: '/admin/index/uploadFile'
        ,before: function(obj){
            obj.preview(function(index, file, result){
                $('#btn4_url').attr('src', result); 
            });
        }
        ,done: function(res){
            if(res.code > 0){
                return layer.msg('上传失败');
            }
            console.log(res.data.src)
            $('#STORE_BANNER').val(res.data.src);
        }
        ,error: function(){
            return layer.msg('上传失败');
        }
    });

    //about banner2
    var uploadInst = upload.render({
        elem: '#btn5'
        ,url: '/admin/index/uploadFile'
        ,before: function(obj){
            obj.preview(function(index, file, result){
                $('#btn5_url').attr('src', result); 
            });
        }
        ,done: function(res){
            if(res.code > 0){
                return layer.msg('上传失败');
            }
            console.log(res.data.src)
            $('#ABOUT_BANNER').val(res.data.src);
        }
        ,error: function(){
            return layer.msg('上传失败');
        }
    });

    var uploadInst = upload.render({
        elem: '#btn6'
        ,url: '/admin/index/uploadFile'
        ,before: function(obj){
            obj.preview(function(index, file, result){
                $('#btn6_url').attr('src', result); 
            });
        }
        ,done: function(res){
            if(res.code > 0){
                return layer.msg('上传失败');
            }
            console.log(res.data.src)
            $('#COLLE_BANNER').val(res.data.src);
        }
        ,error: function(){
            return layer.msg('上传失败');
        }
    });

})